from .play_24_points_game_v2 import call_deal, call_help, call_judge


call_cnt = 0


async def chat_with_agent(user_msg: str):
    global call_cnt

    print(f"Received user message: '{user_msg}'")
    agent_reply = user_msg

    if user_msg == "exit":
        agent_reply = "ok, exit game."
        call_cnt = 0
    elif user_msg == "deal" or call_cnt > 0:
        if user_msg == "deal":
            agent_reply = await call_deal()
        elif user_msg == "help":
            agent_reply = await call_help()
        else:
            agent_reply = await call_judge(user_msg)

        call_cnt += 1
        
    yield ('TEXT', agent_reply)
